<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .box {
      width: 200px;
      height: 200px;
      background-color: skyblue;
      border: 1px solid orange;
    }
  </style>
</head>

<body>
  <div class="box">11</div>
  <ul>
    <li class="item">第1个</li>
    <li class="item">第2个</li>
    <li class="item">第3个</li>
    <li class="item">第4个</li>
    <li class="item">第5个</li>
    <li class="item">第6个</li>
    <li class="item">第7个</li>
  </ul>
  <script>
    var div1 = document.querySelector('.box');//获取单个对象
    div1.onclick = function () {
      console.log(1);
    }
    div1.onclick = function () {
      console.log(2);
    }
    div1.onclick = function () {
      console.log(4);
    }
    div1.addEventListener('click', function () {
      console.log(3);
    })
    div1.addEventListener('click', function () {
      console.log(5);
    })

    var items = document.querySelectorAll('.item');//获取数组

    for (let i = 0; i < items.length; i++) {
      items[i].addEventListener('click', function () {
        console.log(i);
      })

    }

  </script>
</body>

</html>